let serStart =[256, 384, 592, 688, 768, 931, 1024, 1280, 1536, 1566, 1872, 1869, 1984, 2208, 2304, 2451, 3415, 3430,3585, 3840, 4096, 4256, 4352, 4608,
     , 5120, 5760, 5792, 6016, 6176, 6528, 6624, 6656, 7248];
let serEnd   =[383, 591, 687, 767, 879, 1023, 1279, 1327, 1564, 1791, 1969, 1969, 1919, 2223, 2384, 2472, 3427, 3455,3642, 3911, 4255, 4293, 4446, 4680,
     , 5736, 5789, 5872, 6067, 6263, 6571, 6655, 6682, 7295];

let coolDict=new Array();
for(var i=0;i<serStart.length;i++){
    for(var j=serStart[i];j<serEnd[i];j++){
        coolDict.push(j)
    }
}

if (!Array.prototype.shuffle) {
    Array.prototype.shuffle = function() {
        for(var j, x, i = this.length; i; j = parseInt(Math.random() * i), x = this[--i], this[i] = this[j], this[j] = x);
        return this;
    };
}
coolDict=coolDict.shuffle();
coolDict=Array.from(new Set(coolDict));


//装填数组
let parentArrays= new Array();
for(var i=0;i<10;i++){
    parentArrays[i] = new Array();
    for(var j=0;j<10;j++){
        parentArrays[i][j]=coolDict.shuffle();
    }
}

function weakEncrept(objtxt) {
    var txt = objtxt.split('');
    var param = new Array(),xsArry = new Array(),ysArry=new Array();
    var rd1 = parseInt(Math.random() * 10),rd2 = parseInt(Math.random() * 10),rd3=parseInt(Math.random()*10);
    var dictChar=parentArrays[rd1][rd2][rd3];
    param.push(String.fromCharCode(dictChar));
    for(let t of txt){
        t=t.charCodeAt()^dictChar;
        var xs=Math.floor(t/coolDict.length),ys=t%coolDict.length;
        xsArry.push(String.fromCharCode(coolDict[xs]));
        ysArry.push(String.fromCharCode(coolDict[ys]));
    }
    return param.join('') + xsArry.join('')+ysArry.join('');
}


function weakDecrept(objtxt) {
    var srcTxt = objtxt.split('');
    var codeList = srcTxt.slice(0,1);
    var tempList=srcTxt.slice(1);
    var xsList = tempList.slice(0,tempList.length>>1);
    var ysList = tempList.slice(tempList.length >>1)
    var result = new Array();
    for (var i=0;i<xsList.length;i++) {
        var temp=codeList[0].charCodeAt()^(coolDict.indexOf(xsList[i].charCodeAt())*coolDict.length+coolDict.indexOf(ysList[i].charCodeAt()));
        result.push(String.fromCharCode(temp));
    }
    return result.join('');
}




var demo=weakEncrept("有一个人前来买瓜，老板这瓜怎么卖啊，2块钱一斤，what's up? 你这瓜皮子是金粒子做的，还是瓜粒子是金子做的");
console.log(demo);
console.log(weakDecrept(demo));


